home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / COLLECT3.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  2KB  |  94 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {*  Containers Library demo                                               *}
  6. {**************************************************************************}
  7.  
  8. program Collect3;
  9.  
  10. {$X+}
  11.  
  12. { Sample program for using a huge sorted string collection. }
  13.  
  14. uses Objects, Containr, ctCollec,
  15.      {$ifdef Windows}
  16.      WinCtr;
  17.      {$else}
  18.      Crt;
  19.      {$endif}
  20.  
  21. procedure DisplayStrings(StringList : PSequence);
  22.  
  23.   procedure PrintString(Str : PString); far;
  24.   begin
  25.     Writeln(Str^);
  26.   end;
  27.  
  28. begin
  29.   StringList^.ForEach(@PrintString);
  30. end;
  31.  
  32. procedure DisplayFirst(StringList : PSequence);
  33. var
  34.   Item : Pointer;
  35.   Index : LongInt;
  36. begin
  37.   Item := StringList^.First(Index);
  38.   Writeln('First item:');
  39.   writeln(PString(Item)^);
  40.   StringList^.DoneItem(Item); { not required }
  41. end;
  42.  
  43. procedure DisplayLast(StringList : PSequence);
  44. var
  45.   Item : Pointer;
  46.   Index : LongInt;
  47. begin
  48.   Item := StringList^.Last(Index);
  49.   Writeln('Last item:');
  50.   writeln(PString(Item)^);
  51.   StringList^.DoneItem(Item); { not required }
  52. end;
  53.  
  54. procedure FindString(StringList : PSequence;  SearchStr : string);
  55. var
  56.   Index : LongInt;
  57. begin
  58.   if StringList^.Search(@SearchStr, Index)
  59.     then begin
  60.            Writeln('String found:');
  61.            Writeln(PString(StringList^.At(Index))^)
  62.          end { if }
  63.     else Writeln('String not found.');
  64. end;
  65.  
  66. var
  67.   StringList : PHugeStringCollection;
  68.  
  69. begin
  70.   ClrScr;
  71.  
  72.   { Create the collection }
  73.   StringList := New(PHugeStringCollection, Init(50, 10));
  74.  
  75.   { Insert items into the collection }
  76.   with StringList^ do
  77.   begin
  78.     Insert(NewStr('Sky'));
  79.     Insert(NewStr('Absolute'));
  80.     Insert(NewStr('Temporary'));
  81.     Insert(NewStr('Field'));
  82.   end; { with }
  83.  
  84.   DisplayStrings(StringList);
  85.   Writeln;
  86.   DisplayFirst(StringList);
  87.   Writeln;
  88.   DisplayLast(StringList);
  89.   Writeln;
  90.   FindString(StringList, 'Field');
  91.  
  92.   { Dispose of the collection and all the objects in it }
  93.   Dispose(StringList, Done);
  94. end.